const mySqrt = (x) => {
    if (x < 2) return x;
    let l = 1, r = Math.floor(x / 2), mid;
    while (l <= r) {
        mid = l + Math.floor((r - l) / 2)
        if (mid * mid === x) {
            return mid
        }
        if (mid * mid < x) {
            l = mid + 1
        } else {
            r = mid - 1
        }
    }
    return r
}
console.log(mySqrt(7));